from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-07-29 14:02:15.621353
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 29, Jul, 2022
Time: 14:02:20
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.9642
Nobs: 732.000 HQIC: -50.3113
Log likelihood: 9235.74 FPE: 1.13612e-22
AIC: -50.5293 Det(Omega_mle): 1.00552e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299382 0.056414 5.307 0.000
L1.Burgenland 0.107712 0.037099 2.903 0.004
L1.Kärnten -0.106981 0.019663 -5.441 0.000
L1.Niederösterreich 0.208013 0.077654 2.679 0.007
L1.Oberösterreich 0.107004 0.075723 1.413 0.158
L1.Salzburg 0.254036 0.039672 6.403 0.000
L1.Steiermark 0.042346 0.051757 0.818 0.413
L1.Tirol 0.108849 0.041973 2.593 0.010
L1.Vorarlberg -0.062744 0.036176 -1.734 0.083
L1.Wien 0.047515 0.066952 0.710 0.478
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054580 0.117912 0.463 0.643
L1.Burgenland -0.031997 0.077541 -0.413 0.680
L1.Kärnten 0.047006 0.041099 1.144 0.253
L1.Niederösterreich -0.178107 0.162306 -1.097 0.272
L1.Oberösterreich 0.409434 0.158268 2.587 0.010
L1.Salzburg 0.288446 0.082919 3.479 0.001
L1.Steiermark 0.108292 0.108177 1.001 0.317
L1.Tirol 0.311518 0.087728 3.551 0.000
L1.Vorarlberg 0.026105 0.075612 0.345 0.730
L1.Wien -0.028044 0.139938 -0.200 0.841
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187412 0.028878 6.490 0.000
L1.Burgenland 0.090167 0.018990 4.748 0.000
L1.Kärnten -0.009032 0.010065 -0.897 0.370
L1.Niederösterreich 0.261531 0.039750 6.579 0.000
L1.Oberösterreich 0.138198 0.038761 3.565 0.000
L1.Salzburg 0.046244 0.020308 2.277 0.023
L1.Steiermark 0.020855 0.026494 0.787 0.431
L1.Tirol 0.093461 0.021485 4.350 0.000
L1.Vorarlberg 0.056715 0.018518 3.063 0.002
L1.Wien 0.115547 0.034272 3.371 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110542 0.029384 3.762 0.000
L1.Burgenland 0.045710 0.019324 2.365 0.018
L1.Kärnten -0.014017 0.010242 -1.369 0.171
L1.Niederösterreich 0.188425 0.040448 4.658 0.000
L1.Oberösterreich 0.301332 0.039442 7.640 0.000
L1.Salzburg 0.109767 0.020664 5.312 0.000
L1.Steiermark 0.104828 0.026959 3.888 0.000
L1.Tirol 0.105732 0.021862 4.836 0.000
L1.Vorarlberg 0.068328 0.018843 3.626 0.000
L1.Wien -0.021312 0.034873 -0.611 0.541
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.127627 0.053546 2.383 0.017
L1.Burgenland -0.049986 0.035213 -1.420 0.156
L1.Kärnten -0.040989 0.018664 -2.196 0.028
L1.Niederösterreich 0.164872 0.073707 2.237 0.025
L1.Oberösterreich 0.140224 0.071873 1.951 0.051
L1.Salzburg 0.289479 0.037655 7.688 0.000
L1.Steiermark 0.036940 0.049126 0.752 0.452
L1.Tirol 0.163597 0.039839 4.106 0.000
L1.Vorarlberg 0.100479 0.034337 2.926 0.003
L1.Wien 0.069883 0.063549 1.100 0.271
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054584 0.042586 1.282 0.200
L1.Burgenland 0.039507 0.028005 1.411 0.158
L1.Kärnten 0.051019 0.014843 3.437 0.001
L1.Niederösterreich 0.217810 0.058620 3.716 0.000
L1.Oberösterreich 0.296063 0.057161 5.179 0.000
L1.Salzburg 0.043728 0.029948 1.460 0.144
L1.Steiermark 0.001200 0.039070 0.031 0.975
L1.Tirol 0.143312 0.031684 4.523 0.000
L1.Vorarlberg 0.072610 0.027309 2.659 0.008
L1.Wien 0.080931 0.050541 1.601 0.109
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173377 0.050897 3.406 0.001
L1.Burgenland -0.002593 0.033471 -0.077 0.938
L1.Kärnten -0.062644 0.017740 -3.531 0.000
L1.Niederösterreich -0.082155 0.070060 -1.173 0.241
L1.Oberösterreich 0.191521 0.068317 2.803 0.005
L1.Salzburg 0.058279 0.035792 1.628 0.103
L1.Steiermark 0.235605 0.046695 5.046 0.000
L1.Tirol 0.498440 0.037868 13.163 0.000
L1.Vorarlberg 0.045693 0.032638 1.400 0.162
L1.Wien -0.053241 0.060404 -0.881 0.378
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.165487 0.058569 2.825 0.005
L1.Burgenland -0.007999 0.038516 -0.208 0.835
L1.Kärnten 0.065967 0.020415 3.231 0.001
L1.Niederösterreich 0.204076 0.080621 2.531 0.011
L1.Oberösterreich -0.071632 0.078615 -0.911 0.362
L1.Salzburg 0.208447 0.041188 5.061 0.000
L1.Steiermark 0.123288 0.053734 2.294 0.022
L1.Tirol 0.072174 0.043576 1.656 0.098
L1.Vorarlberg 0.120099 0.037558 3.198 0.001
L1.Wien 0.121846 0.069510 1.753 0.080
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.360283 0.033712 10.687 0.000
L1.Burgenland 0.007280 0.022170 0.328 0.743
L1.Kärnten -0.023707 0.011750 -2.018 0.044
L1.Niederösterreich 0.216917 0.046405 4.674 0.000
L1.Oberösterreich 0.198354 0.045250 4.383 0.000
L1.Salzburg 0.043096 0.023707 1.818 0.069
L1.Steiermark -0.013496 0.030929 -0.436 0.663
L1.Tirol 0.104913 0.025082 4.183 0.000
L1.Vorarlberg 0.070760 0.021618 3.273 0.001
L1.Wien 0.037646 0.040009 0.941 0.347
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039865 0.139040 0.191119 0.150858 0.117421 0.103089 0.062506 0.216195
Kärnten 0.039865 1.000000 -0.006960 0.132709 0.039253 0.094327 0.433321 -0.053465 0.097706
Niederösterreich 0.139040 -0.006960 1.000000 0.334925 0.142462 0.293780 0.095219 0.177920 0.314597
Oberösterreich 0.191119 0.132709 0.334925 1.000000 0.228266 0.324735 0.175497 0.164539 0.261287
Salzburg 0.150858 0.039253 0.142462 0.228266 1.000000 0.142145 0.111853 0.145090 0.124410
Steiermark 0.117421 0.094327 0.293780 0.324735 0.142145 1.000000 0.145889 0.137349 0.071279
Tirol 0.103089 0.433321 0.095219 0.175497 0.111853 0.145889 1.000000 0.111574 0.143389
Vorarlberg 0.062506 -0.053465 0.177920 0.164539 0.145090 0.137349 0.111574 1.000000 -0.000783
Wien 0.216195 0.097706 0.314597 0.261287 0.124410 0.071279 0.143389 -0.000783 1.000000